# _*_ coding:utf-8 _*_
#用类实现斐波那契数列的运算（编写自定义迭代器）
class Series:
	def __init__(self):
		self.a = 0
		self.b = 1

	def __iter__(self):
		return self# 本身就是迭代器，所以返回本身

	def __next__(self):
		temp = self.b
		self.b = self.a + self.b
		self.a = temp
		return self.a

lt=[]
a=Series()
for i in a:
    if i>100:
        break
    else:
        lt.append(i)
print(lt)



#自定义异常类：当list内元素长度超过10的时候抛出异常
class ListError(Exception):
    def __init__(self):
        pass
    def __str__(self):
        return "ListError：list内元素长度超过10"

def lst_length(lst1):
    if len(lst1) > 10:
        raise ListError
    else:
        print(len(lst1))

lst = [1,2,3,4,5,6,7,8,9,10,111]
try:
    lst_length(lst)
except ListError:
    print(ListError())

